function CustomerHighSea_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find" class="finds2"><div class="searchinput ui-border-radius"><input id="keyword" class="bordersolid" type="text" value="" onblur="Show_Search()" onkeyup="CustomerHighSea_Search();"/><div id="searchicon" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons" class="searchicons"><img src="img/jings.jpg"/></div></div></div>');
	buffer.append('<div class="horizen border-bottom"></div>');
	return buffer.toString();
};

function CustomerHighSea_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="customerlist border-bottom" id="'+info.ID+'"><div class="customername"><div class="cname">'+info.Name+'</div><div class="cbtn">'+(info.HeadUser==0?'<a onclick="Take_Customer(this)">认领</a>':'已领')+'</div></div><div class="customerinfo"><div class="state">跟进人：'+info.HeadUserName.ToString()+'</div><div class="lastconntime">'+(info.FollowDate.ToTime()!=""?("认领时间："+info.FollowDate.ToTime()):"")+'</div></div></div>');
	});
	return buffer.toString();
};

function Receive_CustomerHighSea(pageindex)
{
	var data = {};
			data.act = "Find_Customer";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword").val();
		    data.timer = "";
		    data.state = "";
		    data.type = 5;
		    data.lowers = "";
		    data.sign=GetSign(data.act);
			
			mui.getJSON(crm_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist1").html(CustomerHighSea_Data(json.data.list));
					}else{
						$("#contentlist1").append(CustomerHighSea_Data(json.data.list));
					}
					setTimeout(function(){
						//Init_CustomerHighSea();
						myScroll1.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.list.length!=data.pagesize)
					{
						$("#loading1").html("");
					}else{
						$("#loading1").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist1").html("");
						$("#loading1").html("主人，没有找到您需要的数据"); 
					}
					else
					{
						$("#loading1").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg1").attr("pageindex"))+1;
         		$("#divmsg1").attr("pageindex",pageindex);
			});
};

function CustomerHighSea_Search(){
	Receive_CustomerHighSea(1);
};

function Init_CustomerHighSea()
{
	mui("#contentlist1").off("tap",".customerlist");
	mui("#contentlist1").on("tap",".customerlist",function(){
		OpenWindow2(2,"客户详情","操作",function(){
			CustomerTool(); 
		});
		obj=$(this);
		$("#contentlist2").append(CustomerInfo_Code());
		get("contentlist2").addEventListener("tap",function(){
			if($(".customertool").length>0)
			{
				$(".customertool").hide();
			}
		});
		Init_CustomerInfo();
	});
};


//认领客户
function Take_Customer(o) {
    var o = $(o).parent().parent().parent();
    plus.nativeUI.confirm("您确定要认领客户【" + o.find(".cname").html() + "】吗？", function(event){
		if(event.index==1)
		{
			var data = {};
	        data.id = o.attr("id");
	        data.act = "Take_Customer";
	        data.cusname = o.find(".cname").html();
	        data.userid=userid;
			data.comid=comid;
	        data.source=source;
	        data.sign=GetSign(data.act);
	        
			mui.getJSON(crm_domain, data, function (json) {
				plus.nativeUI.toast(json.msg); 
	            if (json.state) {
	            	o.find(".cbtn").html("已领");
	                o.find(".state").html("跟进人："+User.RealName);
	                o.find(".lastconntime").html("认领时间："+(new Date()+"").ToTime());
	            }
	        });
		}
	},"提示", ["取消","确认"]); 
};